﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.IO;

namespace WeatherAppService
{

    [ServiceContract]
    public interface IWeatherAppService
    {
        [WebGet(UriTemplate = "users", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnUsers GetAllUsers();

        [WebGet(UriTemplate = "posts", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnPosts GetAllPosts();

        [WebGet(UriTemplate = "{user}/posts", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnPosts GetAllPostsByUser(string user);

        [WebGet(UriTemplate = "login", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnUser GetUserByCredentials();

        [WebInvoke(Method = "POST", UriTemplate = "register", RequestFormat = WebMessageFormat.Json,  ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnUser AddUser(Stream JSONdataStream);

        [WebInvoke(Method = "POST", UriTemplate = "post", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnPosts AddPost(Stream JSONdataStream);      

        [WebInvoke(Method = "POST", UriTemplate = "edit", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnUser EditUser(Stream JSONdataStream);

        [WebInvoke(Method = "POST", UriTemplate = "passrecovery", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnUser PassRecovery();

        [WebInvoke(Method = "DELETE", UriTemplate = "post/{postid}", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnPosts DeletePostByID(string postid);

        [WebInvoke(Method = "DELETE", UriTemplate = "user/{username}", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ReturnUsers DeleteUserByID(string username);
    }

    [Serializable]
    [DataContract]
    public class Post
    {
        [DataMember]
        public string PostId { get; set; }
        [DataMember]
        public string PostMessage { get; set; }
        [DataMember]
        public string PostLocation { get; set; }
        [DataMember]
        public string PostTime { get; set; }
        [DataMember]
        public string UserName { get; set; }
    }

    [DataContract]
    [Serializable]
    public class User
    {
        [DataMember]
        public string UserId { get; set; }
        [DataMember]
        public string UserName { get; set; }
        
        public string Password { get; set; }
        [DataMember]
        public string Email { get; set; }
        [DataMember]
        public string FirstName { get; set; }
        [DataMember]
        public string LastName { get; set; }
    }

    [DataContract]
    [Serializable]
    public class ReturnUser
    {
        [DataMember(EmitDefaultValue = false)]
        public string Success { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public string ErrorMessage { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public User User { get; set; }
    }

    [DataContract]
    [Serializable]
    public class ReturnUsers
    {
        [DataMember(EmitDefaultValue = false)]
        public string Success { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public string ErrorMessage { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public List<User> Users { get; set; }
    }

    [DataContract]
    [Serializable]
    public class ReturnPosts
    {
        [DataMember(EmitDefaultValue = false)]
        public string Success { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public string ErrorMessage { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public List<Post> Posts { get; set; }
    }
}
